<extend name="Public:form_dialog_layout"/>

<block name="dialog_edit">
 
<script type="text/javascript">
	//var zTree;
	//var zTreeOrgs;
/* 	  var settingKeys = {
		async : {
			enable : true,//启用异步加载
			url : "__URL__/AjaxGetAllKeys", //异步请求地址
			type : "get",
			otherParam : {
				"id" : '{$id}'
					//<empty name='id' > "0" <else/> {$id} </empty>  //$('#idtest').val()
			},
			dataFilter : null
		//autoParam:["id", "str1"], //需要传递的参数,为你在ztree中定义的参数名称
		//
		},
		view : {
			selectedMulti : false  //是否多选
		//,addDiyDom: M_AddDiyDom
		},
		check : {
			autoCheckTrigger : false, //自动验证
			chkboxType: { "Y" : "", "N" : "" },  //不级联父节点选择  
			chkStyle : "checkbox",
			enable : true,
			nocheckInherit : false
		},
		data : {
			key : {
				checked : "checked",
				children : "children",
				name : "name",
				title : "name"
			},
			simpleData : {
				enable : true,
				idKey : "id",
				pIdKey : "pid",
				rootPId : 0
			},
			keep : {
				parent : true,
				leaf : true
			},
		},
		callback : {
			onAsyncSuccess : zTreeOnAsyncSuccessKeys,
			onAsyncError : zTreeOnAsyncError,
			onCheck : getSelectedNodesKeys
		}
	};  
	
	
	 
 	var settingOrgs = {
			async : {
				enable : true,//启用异步加载
				url : "__URL__/AjaxGetAllOrgs", //异步请求地址
				type : "get",
				otherParam : {
					"id" : '{$id}'
						//$('#idtest').val()//({$Rs['id']} == "") ? "0" : {$Rs['id']} //$('#idtest').val()
				},
				dataFilter : null
			//autoParam:["id", "str1"], //需要传递的参数,为你在ztree中定义的参数名称
			//
			},
			view : {
				selectedMulti : false  //是否多选
			//,addDiyDom: M_AddDiyDom
			},
			check : {
				autoCheckTrigger : false, //自动验证
				chkboxType: { "Y" : "", "N" : "" },  //不级联父节点选择  
				chkStyle : "checkbox",
				enable : true,
				nocheckInherit : false
			},
			data : {
				key : {
					checked : "checked",
					children : "children",
					name : "name",
					title : "name"
				},
				simpleData : {
					enable : true,
					idKey : "id",
					pIdKey : "pid",
					rootPId : 0
				},
				keep : {
					parent : true,
					leaf : true
				},
			},
			callback : {
				onAsyncSuccess : zTreeOnAsyncSuccessOrgs,
				onAsyncError : zTreeOnAsyncError,
				onCheck : getSelectedNodesOrgs
			}
		}; 
	 

	function zTreeOnAsyncError(event, treeId, treeNode) {
		alert("异步加载失败!");
	}

	  function zTreeOnAsyncSuccessKeys(event, treeId, treeNode, msg) {

		var treeObj = $.fn.zTree.getZTreeObj("j_select_tree_keys");
		treeObj.expandAll(true);
		getSelectedNodesKeys();
		//getRules();
	}  
	
	  function zTreeOnAsyncSuccessOrgs(event, treeId, treeNode, msg) {
		var treeObj = $.fn.zTree.getZTreeObj("j_select_tree_orgs");
		treeObj.expandAll(true);
		//alert("123123123123");
		getSelectedNodesOrgs();
		//getRules();
	}  

	//所选节点
	  function getSelectedNodesKeys() {
			var selectedNode = $.fn.zTree.getZTreeObj("j_select_tree_keys")
					.getCheckedNodes();
			// $('#CheckedRule').val(JSON.stringify(selectedNode));
			var checkedValueID = $('#keysid').val();
			checkedValueID = "";
			var checkedValueName = $('#keysname').val();
			checkedValueName = "";
			//alert("123123123123");
			var tempCheckedValueID = "";
			var tempCheckedValueName = "";
			for (var i = 0; i < selectedNode.length; i++) {
				//alert(selectedNode[i].MenuID);
				tempCheckedValueID += "," + selectedNode[i].id;
				tempCheckedValueName += "," + selectedNode[i].name;
				//$('#CheckedRule').val(checkedValue + "," + selectedNode[i].MenuID);
			}
	
			if (tempCheckedValueID != '') {
				tempCheckedValueID = tempCheckedValueID.substr(1);
			}
			if (tempCheckedValueName != '') {
				tempCheckedValueName = tempCheckedValueName.substr(1);
			}
			$('#keysid').val(tempCheckedValueID);
			$('#keysname').val(tempCheckedValueName);
	}  
	 function getSelectedNodesOrgs() {
			var selectedNode = $.fn.zTree.getZTreeObj("j_select_tree_orgs")
					.getCheckedNodes();
			// $('#CheckedRule').val(JSON.stringify(selectedNode));
			var checkedValueID = $('#orgid').val();
			checkedValueID = "";
			var checkedValueName = $('#orgname').val();
			checkedValueName = "";
			
			var tempCheckedValueID = "";
			var tempCheckedValueName = "";
			for (var i = 0; i < selectedNode.length; i++) {
				//alert(selectedNode[i].MenuID);
				tempCheckedValueID += "," + selectedNode[i].id;
				tempCheckedValueName += "," + selectedNode[i].name;
				//$('#CheckedRule').val(checkedValue + "," + selectedNode[i].MenuID);
			}
			
			if (tempCheckedValueID != '') {
				tempCheckedValueID = tempCheckedValueID.substr(1);
				
				//alert(tempCheckedValueID);
			}
			if (tempCheckedValueName != '') {
				tempCheckedValueName = tempCheckedValueName.substr(1);
				//alert(tempCheckedValueName);
			}
			$('#orgid').val(tempCheckedValueID);
			$('#orgname').val(tempCheckedValueName);
		}  
	
	$.fn.zTree.init($("#j_select_tree_keys"), settingKeys);
	$.fn.zTree.init($("#j_select_tree_orgs"), settingOrgs);
	 */
	
	  function doc_upload_success(file, data) {
        var json = $.parseJSON(data)
        $(this).bjuiajax('ajaxDone', json)
        if (json[BJUI.keys.statusCode] == BJUI.statusCode.ok) {
            $('#doc_pic').val(json.filename)
            $('#doc_span_pic').html('已上传图片：<img src="'+ json.filename +'" width="100">')
        }
	 }

	   $('#startdt').on('afterchange.bjui.datepicker', function(e, data) {
		   
		   newdate=new Date($('#startdt').val());
		   newdate.setDate(newdate.getDate() + 30);

		   //alert(newdate.formatDate('yyyy-MM-dd')); 

		   
		   if($('#enddt').val()=='')
		   {
			   //alert(getNowFormatDate(newdate));
			   $('#enddt').val(newdate.formatDate('yyyy-MM-dd'));
		   }
		}); 
	   
	   // 初期加载 默认日期
	   $(function(){
		   newdate=new Date();
		   //alert(newdate);
		   if($('#startdt').val()=='')
		   {
		   $('#startdt').val(newdate.formatDate('yyyy-MM-dd'));
		   }
		   if($('#enddt').val()=='')
		   {
		   newdate.setDate(newdate.getDate() + 30);
		   $('#enddt').val(newdate.formatDate('yyyy-MM-dd'));
		   }

		   
		   makeTree("__URL__/AjaxGetAllKeys",
				   {id : {$id}},
				   "j_select_tree_keys",
				   '#keysid',
				   '#keysname',
				   $("#j_select_tree_keys")
				   );
		   
		   makeTree("__URL__/AjaxGetAllOrgs",
				   {id : {$id}},
				   "j_select_tree_orgs",
				   '#orgid',
				   '#orgname',
				   $("#j_select_tree_orgs")
				   );
		}); 

	 $('#enddt').on('afterchange.bjui.datepicker', function(e, data) {
		 //checkenddt(e, data);
		}); 

	 function getNowFormatDate(newdate)
	 {
	 var day = new Date(newdate);
	 var Year = 0;
	 var Month = 0;
	 var Day = 0;
	 var CurrentDate = "";
	 //初始化时间
	 //Year= day.getYear();//有火狐下2008年显示108的bug
	 Year= day.getFullYear();//ie火狐下都可以
	 Month= day.getMonth();
	 Day = day.getDate()+30;
	 //Hour = day.getHours();
	 // Minute = day.getMinutes();
	 // Second = day.getSeconds();
	 day.setDate(day.getDate()+30);
	 //xDate=new Date(Year+'-'+Month+'-'+Day);
	 
	 CurrentDate += Year + "-";
	 if (Month >= 10 )
	 {
	 CurrentDate += Month + "-";
	 }
	 else
	 {
	 CurrentDate += "0" + Month + "-";
	 }
	 if (Day >= 10 )
	 {
	 CurrentDate += Day ;
	 }
	 else
	 {
	 CurrentDate += "0" + Day ;
	 }
	 
	
	 formatDate(new Date());
	 return formatDate(new Date());
	 } 
	 
	 function checkenddt(e, data){
		    var startdt =  $('#startdt').val();
		    var enddt= $('#enddt').val();
		     if(enddt<startdt)
		     {
		    	 //sdfsfsdfsf
		    	 $(this).alertmsg('error',"结束日期不能小于开始日期！");
		    	 $('#enddt').val("");
		     }
		}
	 
	 $('form[name="infopublish"]').validator({
		    stopOnError: false,
		    timely: true,
		    fields: {
		        'title': 'required;',
		        'username': 'required;'
		    },
		 	beforeSubmit: function (form){ 
			 	return CommitVerify(form); 
			}
		    ,    //验证成功
		    valid: function(form) {
		    	$(form).bjuiajax('ajaxForm',$(form).data());

		    },
		}); 
	 
	 
</script> 


	<php> //类别初期加载 
	$listInfotype1=M('Infotype')->where( "status='1' and pid=(select pid from ".C('DB_PREFIX')."Infotype where id='".$Rs["infotypeid"]."')" )->select();
	//var_dump($listInfotype1->getLastSql()) ; 
	</php>
	
		<table class="table table-condensed table-hover" width="100%">
			<tbody>
				<tr>
				
					<td colspan="2"><label for="j_title" class="control-label x85">标题：</label>
					<!-- data-rule="标题：required;title"  -->
						<input type="text" 
						size="30"
						name="title" id="j_title"
						value="{$Rs['title']}"
						
						></td>
				</tr>

				<tr>
					<td><label for="j_title" class="control-label x85">发布日期：</label>
						<input type="text" name="startdt" id="startdt"
						data-toggle="datepicker" size="15"
						
						data-min-date="%y-%M-%d"
						
						value="{$Rs['startdt']}"></td>
						
					<td><label for="j_title" class="control-label x85">截止日期：</label>
						<input type="text" name="enddt" id="enddt"
						data-toggle="datepicker" 
						data-rule="截止日期：required;date" size="15"
						value="{$Rs['enddt']}">
						<!-- data-min-date="%y-%M-{%d+30}" -->
						</td>
				</tr>

				<tr>
					<td colspan="2"><label for="j_title" class="control-label x85">类别：</label>
						<select name="infotypeid1" id="InfoType1" data-toggle="selectpicker"
						data-nextselect="#j_form_InfoType2"
						data-refurl="__URL__/getInfoType/infotypeid/{value}"
						
						data-emptytxt="--请选择--">
							<option value="">--请选择--</option>
							<foreach name="infotypelist" item="v">
							<option <if
									condition="$v.id EQ $infotypepid "> selected
								value="{$infotypepid}" <else />value="{$v.id}"</if> >
								{$v.name}
							</option>
							</foreach>
					</select> <select name="infotypeid" id="j_form_InfoType2"
						data-toggle="selectpicker" data-emptytxt="--请选择--"
						data-rule="类别: required;infotypeid"
						>
							<option value="">--请选择--</option>
							<foreach name="listInfotype1" item="v">
							<option <if
									condition="$v.id EQ $Rs['infotypeid'] "> selected
								value="{$Rs['infotypeid']}" <else />value="{$v.id}"</if> >
								{$v.name}
							</option>
							</foreach>
					</select></td>
				</tr>
				<tr>
					<td><label for="j_name" class="control-label x85">重要度：</label>
						<select name="importantid" 
						data-toggle="selectpicker"
						data-rule="重要度: required;importantid"
						data-emptytxt="--请选择--">
							<option value="">--请选择--</option>
							<foreach name="importantlist" item="v">
							<option <if
									condition="$v.id EQ $Rs['importantid'] ">
								selected value="{$Rs['importantid']}" <else />value="{$v.id}"</if>
								> {$v.name}
							</option>
							</foreach>
					</select></td>
					<td><label for="j_title" class="control-label x85">所属部门：</label>
						<input type="text" name="orgname" id="orgname"
						data-toggle="selectztree" size="18"
						data-rule="可见部门: required;orgname"
						data-tree="#j_select_tree_orgs" readonly> <input
						type="hidden" id="orgid" name="orgid" value="">
						<ul id="j_select_tree_orgs" class="ztree hide">
						</ul></td>
				</tr>
				<tr>
					<td colspan="2">
					<label for="j_title" class="control-label x85">关键词：</label>
						<input type="text" name="keysname" id="keysname"
						data-rule="关键词: required;keysname"
						data-toggle="selectztree" size="18"
						data-tree="#j_select_tree_keys" readonly> <input
						type="hidden" id="keysid" name="keysid" value="">
						<ul id="j_select_tree_keys" class="ztree hide">

							<!-- <foreach name="keyslist" item="v">
							<li data-id="{$v.KeysID}" data-pid="{$v.KeysPid}" >{$v.KeysName}</li>
							</foreach> -->
							<!-- <li data-id="1" data-pid="0">表单元素</li>
							<li data-id="10" data-pid="1" data-url="form-button.html"
								data-tabid="form-button">按钮</li>
							<li data-id="11" data-pid="1" data-url="form-input.html"
								data-tabid="form-input">文本框</li>
							<li data-id="12" data-pid="11" data-url="form-select.html"
								data-tabid="form-select">下拉选择框</li>
							<li data-id="13" data-pid="11" data-url="form-checkbox.html"
								data-tabid="table">复选、单选框</li>
							<li data-id="14" data-pid="1" data-url="form.html"
								data-tabid="form">表单综合演示</li>
							<li data-id="2" data-pid="0">表格</li>
							<li data-id="20" data-pid="2" data-url="table.html"
								data-tabid="table">普通表格</li>
							<li data-id="21" data-pid="2" data-url="table-fixed.html"
								data-tabid="table-fixed">固定表头表格</li>
							<li data-id="22" data-pid="2" data-url="table-edit.html"
								data-tabid="table-edit">可编辑表格</li> -->
						</ul></td>
				</tr>
				<tr>
					<td colspan="2">
						<div style="display: inline-block; vertical-align: middle;">
							<textarea name="content" id="j_form_content"
								class="j-content" style="width: 100%" data-toggle="kindeditor"
								data-minheight="200">
							{$Rs['content']}
						</textarea>
						</div>
					</td>
				</tr>

				<tr>
					<td colspan=2>
					<php> //类别初期加载 
					if(!isset($Rs["attid"])&&trim($Rs["attid"])=="")
					{
					  $Rs["attid"]=time();
					}
					</php>
						<label for='attid_input' class='control-label x85'>上传附件:</label>
						<div style='display: inline-block; vertical-align: middle;'>
						<IFRAME   src="__MODULE__/Public/attfile/attid/{$Rs['attid']}"  frameBorder=0 width='100%' height='30' scrolling=no ></IFRAME>
						<input type='hidden' id='attid' name='attid'  value='{$Rs["attid"]}'  >
						</div>
					</td>
				</tr>
					

				<!-- <if condition="$id EQ '' "> <else />
				<tr>
					<td colspan="2"><label for="j_status"
						class="control-label x85">是否启用：</label> <select name="status"
						data-container="body" id="j_status" data-toggle="selectpicker"
						data-rule="required">
							<if condition="$Rs['status'] EQ 1 OR  $Rs['status'] EQ ''">
							<option value="1" selected>启用</option>
							<option value="0">禁用</option>
							<else />
							<option value="1">启用</option>
							<option value="0" selected>禁用</option>
							</if>
					</select></td>
				</tr>
				</if> -->
				<tr>
					<td colspan="2"><label for="j_sort" class="control-label x85">排序：</label>
						<input type="text" size="5" data-toggle="spinner" data-min="0"
						data-max="100" data-step="1" data-rule="integer" name="sort"
						id="j_sort" value="{$Rs['sort']}"></td>
				</tr>
			</tbody>
		</table>
</block>


